import { defineStore } from 'pinia';
import { OnePageType, DataItemInput, DataItemBody, DataItemBack } from '@/pages/interfaceto/type/index';

export const useStore = defineStore('interPinia', {
  state: () => ({
    debug: import.meta.env.MODE === 'development',
    isInitialized: false,
    count: 0,
    test: 0,
    peopleOnePageNewData: {
      dirId: 999,
      portsSource: '',
      portsOutTime: 30,
      portsStatus: 69,
      portsRequestMethod: 2,
      portsName: '',
      portsProtocol: 1,
      portsPath: '',
      portsMsg: '',
      portsIp: '',
    } as OnePageType,
    dataSource1: [] as DataItemInput[],
    dataSource2: [] as DataItemBody[],
    dataSource3: [] as DataItemBack[],
  }),

  actions: {
    initApp() {
      this.isInitialized = true;
      console.log('app initialized!');
    },

    increment(value = 1) {
      this.count += value;
    },
    getdataSourceone(data: DataItemInput[]) {
      this.dataSource1 = data;
      // this.dataSource1.dirId = this.$state.peopleOnePageNewData.dirId;
    },
    getdataSourcetwo(data: DataItemBody[]) {
      this.dataSource2 = data;
    },
    getdataSourcethree(data: DataItemBack[]) {
      this.dataSource3 = data;
    },
    getPeopleOnePageNewData(data?: OnePageType) {
      console.log('执行了外面');

      if (data) {
        console.log('执行了里面');

        this.peopleOnePageNewData = data;
      } else {
        this.peopleOnePageNewData = {
          dirId: 999,
          portsSource: '',
          portsOutTime: 30,
          portsStatus: 69,
          portsRequestMethod: 2,
          portsName: '',
          portsProtocol: 1,
          portsPath: '',
          portsMsg: '',
          portsIp: '',
        } as OnePageType;
      }
    },
  },

  getters: {
    isReady: state => {
      return !state.isInitialized;
    },
  },
});
